package com.newbingo.entity;

import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import com.newbingo.domain.common.EntitySupport;
import com.newbingo.domain.common.Identity;

@Entity
public class BettingItem extends EntitySupport<BettingItem, Integer> implements java.io.Serializable {
	@Identity
	private Integer itemid;
	private BettingCell bettingCell;
	private PeriodGame periodGame;
	private Member member;
	private int amount;
	private Date betTime;
	private Integer win;
	private Integer betResult;
	//抽水金额
	private Integer profixAmount;
	

	public Integer getBetResult() {
		return betResult;
	}

	public void setBetResult(Integer betResult) {
		this.betResult = betResult;
	}

	public BettingItem(){
		
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Integer getItemid() {
		return itemid;
	}

	public void setItemid(Integer itemid) {
		this.itemid = itemid;
	}
	
	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	@JoinColumn(name = "bettingcell_id")
	public BettingCell getBettingCell() {
		return bettingCell;
	}

	public void setBettingCell(BettingCell bettingCell) {
		this.bettingCell = bettingCell;
	}

	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	@JoinColumn(name = "periodGame_pgno")
	public PeriodGame getPeriodGame() {
		return periodGame;
	}
	public void setPeriodGame(PeriodGame periodGame) {
		this.periodGame = periodGame;
	}
	public int getAmount() {
		return amount;
	}
	public void setAmount(int amount) {
		this.amount = amount;
	}
	public Date getBetTime() {
		return betTime;
	}
	public void setBetTime(Date betTime) {
		this.betTime = betTime;
	}

//	@Column(name="win",columnDefinition="Integer default 0")
//	public Integer isWin() {
//		return win;
//	}
//    
//	public void setWin(Integer win) {
//		this.win = win;
//	}

	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	@JoinColumn(name = "member_uno")
	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	@Column(name="win",columnDefinition="Integer default 0")
	public Integer getWin() {
		return win;
	}

	public void setWin(Integer win) {
		this.win = win;
	}
	
	public Integer getProfixAmount() {
		return profixAmount;
	}

	public void setProfixAmount(Integer profixAmount) {
		this.profixAmount = profixAmount;
	}
	
	/*
	 * 判断中奖情况，并进行计算输赢
	 */
	public void getPayout(){
		//判断会员投注是否中奖,1、中奖，修改会员的账户余额和投注项信息,计算抽水金额;0、账户余额不变，投注项为未中奖,抽水为0
		if(this.win==1){
			this.betResult=(int)(this.getBettingCell().getRate()*this.amount);
			this.member.getAccount().setAmount(this.member.getAccount().getAmount()+this.betResult);
			this.profixAmount=this.amount*2-this.betResult;
		}else if(this.win==0){
			this.betResult=0;
			this.profixAmount=0;
		}
	}


}
